package cbfg.vbinding

import javafx.event.ActionEvent
import javafx.event.EventHandler
import javafx.scene.Scene
import javafx.stage.Stage

/**
 * @author: TomHawk
 * @description: ViewBinding 使用示例页
 * @date: 2025/9/3 14:06
 */
class ViewBindingController {
    //fxml 布局与生成的 ViewBinding 类名称及路径对应关系：
    //resources/a.fxml -> ABinding
    //resources/cbfg/vbinding/view-binding.fxml -> cbfg.vbinding.ViewBindingBinding
    private val binding = ViewBindingBinding.bind()
    //也可以通过传入 fxml 布局路径进行绑定：
    //private val binding= ViewBindingBinding.bind("/cbfg/vbinding/view-binding.fxml")

    init {
        binding.btnHello.onAction = EventHandler<ActionEvent> {
            binding.welcomeText.text = "Welcome to ViewBinding!"
        }
    }

    companion object {
        fun show(stage: Stage) {
            val viewBindingLayoutView = ViewBindingController().binding.root
            val scene = Scene(viewBindingLayoutView, 320.0, 240.0)
            stage.title = "ViewBinding 示例页"
            stage.scene = scene
            stage.show()
        }
    }
}